package com.qf.game.servlet;

import com.qf.framwork.annotation.ResponseBody;
import com.qf.framwork.base.BaseServlet;
import com.qf.game.service.GameService;
import com.qf.game.utils.RoomManagerUtils;
import com.qf.game.websocket.entity.Room;

import javax.servlet.annotation.WebServlet;
import java.util.List;

/**
 * description:
 * author: Ken
 * 公众号：Java架构栈
 */
@WebServlet(urlPatterns = "/roomServlet")
public class RoomServlet extends BaseServlet {

    private GameService gameService = new GameService();

    /**
     * @param room
     * @return
     */
    @ResponseBody
    public String createRoom(Room room){
        int rid = gameService.createRoom(room);
        return "{\"rid\":" + rid + "}";
    }

    /**
     * 查询房间列表 返回当前房间对象
     * @return
     */
    @ResponseBody
    public List<Room> roomList(){
        List<Room> rooms = RoomManagerUtils.getRooms();
        return rooms;
    }
}
